<?php
/**
 * Created by PhpStorm.
 * User: kongjg
 * Date: 16/8/7
 * Time: 下午7:05
 */
require_once("SiteRestHandler.php");


$http_method = $_SERVER['REQUEST_METHOD'];
switch($http_method){

    case 'GET':
        $view = "";
        if(!empty($_GET["view"])){
            $view = $_GET["view"];

            /*
             * RESTful service 控制器
             * URL 映射
            */
            switch($view){

                case "labels":
                    $siteRestHandler = new SiteRestHandler();
                    $siteRestHandler->getLabels();
                    break;

                case "":
                    //404 - not found;
                    break;
            }
        }else{echo file_get_contents('README');}
        break;

    case 'POST':
        $id = "";
        $title = "";
        $desc = "";

        if(!empty($_POST["l_id"])){
            $id = $_POST["l_id"];
            $title = $_POST['l_title'];
            $desc = $_POST['l_desc'];

            $siteRestHandler = new SiteRestHandler();
            $siteRestHandler->postLabels($id,$title,$desc);
        }else{echo 'empty value';}
        break;

    case 'DELETE':
        echo 'delete';
        break;
    case 'PUT':
        echo 'put';
        break;
}

?>
